<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<lv-form [formGroup]="formGroup" [lvLabelColon]="false" class="formGroup" lvKeepRequiredWidth>
    <ng-container *ngIf="!isNdmp && isOceanProtect && tapeCopy && restoreType !== restoreTypeEnum.FileRestore">
        <lv-form-item>
        <lv-form-label>{{'protection_tape_all_restore_label' | i18n}}</lv-form-label>
        <lv-form-control>
            <lv-switch formControlName="isDirectRecovery"></lv-switch>
        </lv-form-control>
        </lv-form-item>
    </ng-container>
    
    <lv-form-item>
        <lv-form-label>{{'protection_restore_to_label' | i18n}}</lv-form-label>
        <lv-form-control>
            <lv-radio-group formControlName="restoreLocation">
                <lv-group [lvGutter]="'30px'">
                    <lv-radio [lvValue]="restoreLocationType.ORIGIN"
                        [lvDisabled]="restoreToNewLocationOnly || rowCopy?.resource_status === 'NOT_EXIST'"
                        [lv-tooltip]="rowCopy?.resource_status === 'NOT_EXIST' ?
                        ('protection_cloud_origin_restore_disabled_label' | i18n) :
                        restoreToNewLocationOnly ?
                        ('protection_origin_restore_disabled_label'| i18n) :
                        ''">
                        {{'common_restore_to_origin_location_label' | i18n}}
                    </lv-radio>
                    <lv-radio [lvValue]="restoreLocationType.NEW">{{'common_restore_to_new_location_label' | i18n}}
                    </lv-radio>
                    <lv-radio *ngIf="restoreType === restoreTypeEnum.FileRestore && !isNdmp"
                        [lvValue]="restoreLocationType.NATIVE">
                        {{'protection_native_position_label' | i18n}}
                    </lv-radio>
                </lv-group>
            </lv-radio-group>
        </lv-form-control>
    </lv-form-item>
    <ng-container *ngIf="formGroup.value.restoreLocation === restoreLocationType.ORIGIN">
        <lv-form-item>
            <lv-form-label>{{'common_location_label' | i18n}}</lv-form-label>
            <lv-form-control>
                <input lv-input type="text" formControlName="originalLocation" />
            </lv-form-control>
        </lv-form-item>
        <ng-container *ngIf="(isNasFileSystemFileRestore || isCloudArchiveCopy) && !isNdmp">
            <lv-alert lvType="info" lvClosable="false">
                <span
                    innerHTML="{{(fileShareMode === dataMap.Shared_Mode.nfs.value ? 'protection_nas_share_nfs_restore_label' : 'protection_nas_share_restore_label') | i18n}}"></span>
            </lv-alert>
            <lv-form-item>
                <lv-form-label>{{'explore_share_name_label' | i18n}}</lv-form-label>
                <lv-form-control>
                    <lv-select formControlName="share" [lvOptions]='shareOptions' lvValueKey="key" lvShowFilter
                        lvFilterKey='label' lvFilterMode='contains'>
                    </lv-select>
                </lv-form-control>
            </lv-form-item>
            <lv-form-item>
                <lv-form-label lvRequired>
                    {{'protection_fqdn_ip_label' | i18n}}
                    <i lv-icon="aui-icon-help" lv-tooltip="{{'protection_fqdn_ip_desc_label' | i18n}}"
                        class="configform-constraint" lvColorState='true'></i>
                </lv-form-label>
                <lv-form-control [lvErrorTip]="baseUtilService.ipErrorTip">
                    <input lv-input type="text" formControlName="shareIp" />
                </lv-form-control>
            </lv-form-item>
            <lv-form-item *ngIf="fileShareMode === dataMap.Shared_Mode.cifs.value">
                <lv-form-label lvRequired>
                    {{'protection_auth_method_label' | i18n}}
                </lv-form-label>
                <lv-form-control>
                    <lv-select formControlName="auth_mode" [lvOptions]='authModeOptions' lvValueKey='value'>
                    </lv-select>
                </lv-form-control>
            </lv-form-item>
            <ng-container *ngIf="formGroup.value.auth_mode === dataMap.Nas_Share_Auth_Mode.password.value">
                <lv-form-item>
                    <lv-form-label>{{'common_domain_label' | i18n}}</lv-form-label>
                    <lv-form-control>
                        <input lv-input formControlName="domain" type="text" />
                    </lv-form-control>
                </lv-form-item>
                <lv-form-item>
                    <lv-form-label lvRequired>{{'common_username_label' | i18n}}</lv-form-label>
                    <lv-form-control>
                        <input lv-input formControlName="username" type="text" />
                    </lv-form-control>
                </lv-form-item>
                <lv-form-item>
                    <lv-form-label lvRequired>{{'common_password_label' | i18n}}</lv-form-label>
                    <lv-form-control>
                        <aui-inupt-with-eye formControlName="password"></aui-inupt-with-eye>
                    </lv-form-control>
                </lv-form-item>
            </ng-container>
            <ng-container *ngIf="formGroup.value.auth_mode === dataMap.Nas_Share_Auth_Mode.kerberos.value">
                <lv-form-item>
                    <lv-form-label lvRequired>
                        {{'protection_select_kerberos_label' | i18n}}
                    </lv-form-label>
                    <lv-form-control>
                        <lv-group lvGutter='8px'>
                            <lv-select formControlName="kerberos" [lvOptions]='kerberosOptions' lvValueKey='value'
                                lvShowFilter lvFilterKey='label' lvFilterMode='contains'>
                            </lv-select>
                            <button lv-button (click)='createKerberos()'>
                                {{'common_create_label' | i18n}}
                            </button>
                        </lv-group>
                    </lv-form-control>
                </lv-form-item>
            </ng-container>
        </ng-container>
    </ng-container>
    <ng-container *ngIf="formGroup.value.restoreLocation === restoreLocationType.NEW">
        <lv-form-item>
            <lv-form-label lvRequired>{{'protection_storage_device_label' | i18n}}</lv-form-label>
            <lv-form-control>
                <lv-select formControlName="equipment" [lvOptions]='equipmentOptions' lvValueKey="uuid"
                    lvPlaceholder="{{'common_select_label'|i18n}}" lvShowFilter lvFilterKey='label'
                    lvFilterMode='contains' [lvVirtualScroll]="equipmentOptions.length > 10">
                </lv-select>
            </lv-form-control>
        </lv-form-item>
        <ng-container *ngIf="formGroup.value.equipment && isDoradoEquipment">
            <lv-form-item>
                <lv-form-label lvRequired>{{'common_file_system_label' | i18n}}</lv-form-label>
                <lv-form-control>
                    <lv-select formControlName="fileSystem" [lvOptions]='fileSystemOptions' lvValueKey="uuid"
                        lvShowFilter lvFilterKey='label' lvFilterMode='contains'
                        [lvVirtualScroll]="fileSystemOptions.length > 10">
                    </lv-select>
                </lv-form-control>
            </lv-form-item>
        </ng-container>
        <!-- NDMP恢复目录 -->
        <lv-form-item *ngIf="isNdmpPath && this.formGroup.value.fileSystem">
            <lv-form-label lvRequired>
                {{'common_directory_label' | i18n}}
            </lv-form-label>
            <lv-form-control [lvErrorTip]="directoryErrorTip">
                <input lv-input type="text" formControlName="fullName" />
            </lv-form-control>
        </lv-form-item>
        <ng-container *ngIf="formGroup.value.equipment && !isNdmp">
            <lv-alert lvType="info" lvClosable="false">
                <span
                    innerHTML="{{(fileShareMode === dataMap.Shared_Mode.nfs.value ? 'protection_nas_share_nfs_restore_label' : 'protection_nas_share_restore_label') | i18n}}"></span>
            </lv-alert>
            <lv-form-item>
                <lv-form-label lvRequired>{{'explore_share_name_label' | i18n}}</lv-form-label>
                <lv-form-control>
                    <ng-container *ngIf="!(formGroup.value.equipment && !isDoradoEquipment)">
                        <lv-select formControlName="share" [lvOptions]='shareOptions' lvValueKey="key" lvShowFilter
                            lvFilterKey='label' lvFilterMode='contains'>
                        </lv-select>
                    </ng-container>
                    <ng-container *ngIf="formGroup.value.equipment && !isDoradoEquipment">
                        <lv-group lvGutter='8px'>
                            <lv-select formControlName="share" [lvOptions]='shareOptions' lvValueKey="key" lvShowFilter
                                lvFilterKey='label' lvFilterMode='contains'>
                            </lv-select>
                            <button *ngIf="isSupportReg" lv-button (click)='createNasShare()'>
                                {{'common_register_label' | i18n}}
                            </button>
                        </lv-group>
                    </ng-container>
                </lv-form-control>
            </lv-form-item>
        </ng-container>
        <ng-container *ngIf="isDoradoEquipment">
            <lv-form-item>
                <lv-form-label lvRequired>
                    {{'protection_fqdn_ip_label' | i18n}}
                    <i lv-icon="aui-icon-help" lv-tooltip="{{'protection_fqdn_ip_desc_label' | i18n}}"
                        class="configform-constraint" lvColorState='true'></i>
                </lv-form-label>
                <lv-form-control [lvErrorTip]="baseUtilService.ipErrorTip">
                    <input lv-input type="text" formControlName="shareIp" />
                </lv-form-control>
            </lv-form-item>
        </ng-container>
        <ng-container *ngIf="isDoradoEquipment">
            <lv-form-item *ngIf="fileShareMode === dataMap.Shared_Mode.cifs.value">
                <lv-form-label lvRequired>
                    {{'protection_auth_method_label' | i18n}}
                </lv-form-label>
                <lv-form-control>
                    <lv-select formControlName="auth_mode" [lvOptions]='authModeOptions' lvValueKey='value'>
                    </lv-select>
                </lv-form-control>
            </lv-form-item>
            <ng-container *ngIf="formGroup.value.auth_mode === dataMap.Nas_Share_Auth_Mode.password.value">
                <lv-form-item>
                    <lv-form-label>{{'common_domain_label' | i18n}}</lv-form-label>
                    <lv-form-control>
                        <input lv-input formControlName="domain" type="text" />
                    </lv-form-control>
                </lv-form-item>
                <lv-form-item>
                    <lv-form-label lvRequired>{{'common_username_label' | i18n}}</lv-form-label>
                    <lv-form-control>
                        <input lv-input formControlName="username" type="text" />
                    </lv-form-control>
                </lv-form-item>
                <lv-form-item>
                    <lv-form-label lvRequired>{{'common_password_label' | i18n}}</lv-form-label>
                    <lv-form-control>
                        <aui-inupt-with-eye formControlName="password"></aui-inupt-with-eye>
                    </lv-form-control>
                </lv-form-item>
            </ng-container>
            <ng-container *ngIf="formGroup.value.auth_mode === dataMap.Nas_Share_Auth_Mode.kerberos.value">
                <lv-form-item>
                    <lv-form-label lvRequired>
                        {{'protection_select_kerberos_label' | i18n}}
                    </lv-form-label>
                    <lv-form-control>
                        <lv-group lvGutter='8px'>
                            <lv-select formControlName="kerberos" [lvOptions]='kerberosOptions' lvValueKey='value'
                                lvShowFilter lvFilterKey='label' lvFilterMode='contains'>
                            </lv-select>
                            <button lv-button (click)='createKerberos()'>
                                {{'common_create_label' | i18n}}
                            </button>
                        </lv-group>
                    </lv-form-control>
                </lv-form-item>
            </ng-container>
        </ng-container>
    </ng-container>
    <ng-container>
        <ng-container *ngIf="rowCopy.resource_sub_type === dataMap.Resource_Type.NASShare.value || isShowChannels">
            <lv-form-item>
                <lv-form-label>{{ 'protection_channel_number_label' | i18n }}
                    <i lv-icon="aui-icon-help" [lv-tooltip]="tipsLabel" lvTooltipTheme="light"
                        class="configform-constraint" lvColorState="true"></i>
                </lv-form-label>
                <lv-form-control [lvErrorTip]="channelsErrorTip">
                    <input lv-input type="text" formControlName="channels" placeholder="1-40" />
                </lv-form-control>
            </lv-form-item>
        </ng-container>
        <ng-container *ngIf="exterAgent">
            <lv-form-item>
                <lv-form-label lvRequired>
                    {{'protection_proxy_host_label' | i18n}}
                </lv-form-label>
                <lv-form-control [lvErrorTip]="baseUtilService.requiredErrorTip">
                    <aui-agent-select [lvOptions]="hostOptions" formControlName="proxyHost" lvValueKey="value"
                        lvMode="multiple">
                    </aui-agent-select>
                </lv-form-control>
            </lv-form-item>
        </ng-container>
    </ng-container>

    <ng-container *ngIf="formGroup.value.restoreLocation === restoreLocationType.NATIVE">
        <!-- 仅副本数据生成方式为对象存储归档时，节点可选 -->
        <lv-form-item *ngIf="isOceanProtect">
            <lv-form-label lvRequired>{{'system_servers_label' | i18n}}</lv-form-label>
            <lv-form-control>
                <lv-select formControlName="memberEsn" [lvOptions]='onlineNodeOps' lvValueKey="value"
                    [lvDisabled]="!objStorageArchival">
                </lv-select>
                <div *ngIf="abNormalFlag && !objStorageArchival">
                    <i lv-icon="lv-icon-status-info" class="tip-icon" lvColorState='true'></i>
                    <span class="tip-content">
                        {{'protection_nars_abnormal_node_tips_label' | i18n}}
                    </span>
                </div>
            </lv-form-control>
        </lv-form-item>
        <lv-form-item>
            <lv-form-label lvRequired>{{'common_file_system_label'|i18n}}</lv-form-label>
            <lv-form-control>
                <lv-group [lvColumns]='["auto", "120px"]' lvGutter='8px'>
                    <lv-select formControlName="fileSystem" [lvOptions]='nativeFileSystemOptions' lvValueKey="key"
                        lvShowFilter lvFilterKey='label' lvFilterMode='contains'
                        [lvDisabled]="isOceanProtect && !formGroup.value.memberEsn">
                    </lv-select>
                    <button lv-button (click)='createFileSystem()'
                        [disabled]="isOceanProtect && !formGroup.value.memberEsn">
                        {{'common_create_label' | i18n}}
                    </button>
                </lv-group>
            </lv-form-control>
        </lv-form-item>
    </ng-container>
    <ng-container
        *ngIf="formGroup.value.restoreLocation === restoreLocationType.NEW || rowCopy.resource_sub_type === dataMap.Resource_Type.NASShare.value || restoreType === restoreTypeEnum.FileRestore || isCloudArchiveCopy">
        <lv-form-item>
            <lv-form-label>{{'protection_over_write_rule_label' | i18n}}</lv-form-label>
            <lv-form-control>
                <lv-radio-group formControlName="originalType">
                    <lv-group [lvGutter]="'20px'" lvDirection='vertical' class="mgt-8">
                        <lv-radio [lvValue]="fileReplaceStrategy.Replace">{{'protection_overwrite_label' | i18n}}
                        </lv-radio>
                        <ng-container
                            *ngIf="!(rowCopy.resource_sub_type === dataMap.Resource_Type.ndmp.value && this.resourceObj?.extendInfo?.protocol === dataMap.NasFileSystem_Protocol.ndmp.value) && !isNdmpPath">
                            <lv-radio [lvValue]="fileReplaceStrategy.Ignore">{{'protection_skip_label' |
                                i18n}}</lv-radio>
                            <lv-radio [lvValue]="fileReplaceStrategy.ReplaceOldFile">
                                {{'protection_restore_replace_older_label' | i18n}}</lv-radio>
                        </ng-container>
                    </lv-group>
                </lv-radio-group>
            </lv-form-control>
        </lv-form-item>
    </ng-container>
</lv-form>